<?php

namespace app\model;

use think\Model;

class OrderStatus extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'order_status';

    function getdatalist()
    {
        $ptypeArray = $this->find()
            ->asArray()
            ->all();

        return $ptypeArray;
    }

    public static function listname($ptype)
    {
        $OrderStatus = OrderStatus::where('status', 1)
            ->order('id asc')
            ->select()
            ->toArray();
        if ($ptype == 2) {
            foreach ($OrderStatus as &$vo) {
                $vo['name'] = $vo['name_yuyue'];
            }
        }

        $data[0]['id'] = 0;
        $data[0]['weid'] = 0;
        $data[0]['name'] = '全部';
        $data[0]['status'] = 1;

        $data = array_merge($data, $OrderStatus);
        return $data;
    }

    public static function get_order_status_name_yuyue($id)
    {

        $ret = self::find($id);
        if (!empty($ret)) {
            return $ret->name_yuyue;
        }
    }

    public static function get_order_status_name($id)
    {

        $ret = self::find($id);
        if (!empty($ret)) {
            $ret = $ret->toArray();
            return $ret['name'];
        }
    }

    public static function getpcarray()
    {
        $data = self::field('id,name')->select()->toArray();

        $datalist = [];
        foreach ($data as $key => $vo) {
            $datalist[$key]['val'] = $vo['id'];
            $datalist[$key]['key'] = $vo['name'];
        }
        return $datalist;
    }
    public static function getallarray()
    {
        $data = self::field('id,name')->select()->toArray();
        $datalist = [];
        foreach ($data as $vo) {
            $datalist[$vo['id']] = $vo;
        }
        return $datalist;
    }
}
